{extend name="common/common" /}
{block name="style"}
<style media="screen">
	.curForm .el-input__inner{
		width: 217px;
	}
</style>
{/block}
{block name="content"}
<el-col :lg="12">
	<div class="ibox-title">
		<h5>职员添加</h5>
	</div>
	<div class="ibox-content">
		<el-form label-width="80px" :model="form" :rules="rules" ref="form" class="curForm">
			<el-form-item label="登陆账号" prop="user_name">
				<el-input v-model="form.user_name" required></el-input>
			</el-form-item>
			<el-form-item label="职员角色" prop="role_id">
				<el-select v-model="form.role_id" placeholder="职员角色" filterable>
					{if !empty($role)}
					{foreach name="role" item="vo"}
					<el-option label="{$vo.role_name}" value="{$vo.id}"></el-option>
					{/foreach}
					{/if}
				</el-select>
			</el-form-item>
			<el-form-item label="登陆密码" prop="password">
				<el-input v-model="form.password"></el-input>
			</el-form-item>
			<el-form-item label="职员姓名" prop="real_name">
				<el-input v-model="form.real_name"></el-input>
			</el-form-item>
			<el-form-item label="是否启用">
				<el-radio-group v-model="form.status">
					<el-radio :label="1">正常</el-radio>
					<el-radio :label="2">禁用</el-radio>
				</el-radio-group>
			</el-form-item>
			<el-form-item label="">
				<el-button type="primary" plain @click="subForm('form')">提交</el-button>
			</el-form-item>
		</el-form>
	</div>
</el-col>
{/block}

{block name="script"}
<script type="text/javascript">
var main = new Vue({
	el:"#main",
	data:function() {
		return {
			loading:false,
			form:{
				staff_id:"{$staff_id|default=''}",
				user_name:"",
				role_id:"",
				password:"",
				real_name:"",
				status:1
			},
			rules:{
				user_name:[{required:true,message:'请输入登陆账号',trigger:['blur','change']}],
				role_id:[{required:true,message:'请选择职员角色',trigger:['blur','change']}],
				password:[{required:true,message:'请输入登陆密码',trigger:['blur','change']}],
				real_name:[{required:true,message:'请输入职员姓名',trigger:['blur','change']}]
			}
		}
	},
	methods:{
		subForm(form){
			this.$refs[form].validate((valid) => {
				if (valid) {
					var param = this.form;
					$.post("{:url('user/useradd')}",param,function(res){
						if(res.code == 1){
							main.$confirm('职员添加成功', '成功', {
								confirmButtonText: '确定',
								showClose:false,
								type: 'success',
								showCancelButton:false
							}).then(() => {
								window.location.href = res.data;
							});
						}else{
							main.$notify.error({
								title: '错误',
								message: res.msg
							});
						}
					})
				}
        	});
		}
	}
})
</script>
{/block}
